@extends('admin.base')
@section('title', 'Banner列表')
@section('content')
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <div class="layui-field-box">
            <span class="layui-breadcrumb" lay-separator=">>">
                <a class="layui-btn-sm" href="{{url('admin/banner/index')}}"
                   style="cursor:pointer;"><cite>Banner列表</cite></a>;
            </span>
            </div>
        </fieldset>
        <div class="layui-card-header">
            <div>
                <span class="pull-right">
                <button class="layui-btn layui-btn-sm" onclick="active('{{url('admin/banner/add')}}','','添加Banner');" >
                <i class="layui-icon">&#xe608;</i> 添加Banner
                </button>
                </span>
            </div>
        </div>

        <div class="layui-card-body">
            <style>
                table tr td.tc, table tr th.tc {
                    text-align: center;
                    cursor: default;
                }
            </style>
            <table class="layui-table" lay-even lay-size="">
                <colgroup>
                    <col width="">
                    <col width="">
                    <col width="">
                    <col width="">
                </colgroup>
                <thead>
                <tr>
                    <th class="tc">ID</th>
                    <th class="tc">Banner</th>
                    <th class="tc">排序</th>
                    <th class="tc">状态</th>
                    <th class="tc">创建时间</th>
                    <th class="tc">操作</th>
                </tr>
                <tbody>
                @if($list->isEmpty())
                    <tr>
                        <td colspan="6" class="tc">暂无数据</td>
                    </tr>
                @else
                    @foreach ($list as $v)
                        <tr>
                            <td class="tc">{{$v->id}}</td>
                            <td class="tc"><a href="{{ $v->picname }}" target="_blank"><img src="{{ $v->picname }}"></a></td>
                            <td class="tc">
                                <a href="javascript:void(0);" onclick="active('{{url('admin/banner/sort')}}','{{$v['id']}}','编辑banner排序');">{{ $v->sort }}</a></td>
                            <td class="tc">
                                <form class="layui-form " action="">
                                    <input type="checkbox" @if($v['state']==1) checked @endif name="" lay-skin="switch" lay-filter="switchTest" lay-text="启用|禁用" value="{{ $v['id'] }}">
                                    {{--<input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">--}}

                                </form>

                            </td>
                            <td class="tc">{{ $v->created_at }}</td>
                            <td class="tc">
                                <div class="layui-btn-group">
                                    <button type="button" class="layui-btn layui-btn-danger" onclick="del('{{url('admin/banner/del')}}','{{$v['id']}}');">删除</button>
                                </div>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
                </thead>
            </table>
            <!-- 分页 -->
            <div class="sabrosus">{{ $list->links() }}</div>
        <!-- {{$list->total()}} -->
        </div>

    </div>
@endsection
@section('js')
    <script>
        layui.use('form', function () {
            var form = layui.form;

            //搜索
            form.on('submit(selectsub)', function (data) {
                let keywords = $('#sub_keywords').val();//关键字
                let sh_state = $("[name=sh_state]").val();
                location.href = "{{url('admin/auth/index')}}" + "?keywords=" + keywords+"&state="+ sh_state;
                return false;
            });

            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                var id = data.value;

                if (data.elem.checked) {
                    var state = 1;//启用
                } else {
                    var state = 2;//禁用
                }
                ajax('/admin/banner/up_state', {id: id, state: state});
            });
        });

        function auth_ok(url,id,state){
            layer.confirm('确认通过？', {
                btn : [ '确定', '取消' ]//按钮
            }, function(index) {

                layer.close(index);
                //此处请求后台程序，下方是成功后的前台处理……
                $.ajax({
                    url:url,
                    type:'post',
                    async:false,
                    data:{'id':id,'state':state},
                    success:function(data){
                        layer.msg(data.msg);
                        location.href=location.href;
                    },
                    error:function(){

                    }
                })
            });
        }
    </script>
@endsection